﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

namespace Eugenhome.Atrium.Mail
{
    /// <summary>
    /// 
    /// </summary>
    public class GadagetMessage
    {
        /// <summary></summary>
        public int ID { get; set; }

        /// <summary></summary>
        public string RefID { get; set; }

        /// <summary></summary>
        public string Subj { get; set; }

        /// <summary></summary>
        public string From { get; set; }

        /// <summary></summary>
        public string FromName { get; set; }

        /// <summary></summary>
        public bool IsNew { get; set; }

        /// <summary></summary>
        public string RefsString { get; set; }

        /// <summary></summary>
        [XmlIgnore]
        public string OpenLink { get; set; }

        /// <summary></summary>
        [XmlIgnore]
        public List<string> Refs { get { return RefsString.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList(); } }

        /// <summary></summary>
        [XmlIgnore]
        public List<GadagetMessage> Childs { get; set; }

        /// <summary></summary>
        [XmlIgnore]
        public string Method { get { return _parentCollection.Method; } }

        /// <summary></summary>
        private GadagetMessageCollection _parentCollection;

        /// <summary>
        /// Für die Serialisierung
        /// </summary>
        public GadagetMessage() { IsNew = false; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parentCollection"></param>
        public GadagetMessage(GadagetMessageCollection parentCollection) { IsNew = false; _parentCollection = parentCollection; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="parentCollection"></param>
        /// <param name="id"></param>
        /// <param name="refId"></param>
        /// <param name="subj"></param>
        /// <param name="from"></param>
        /// <param name="fromName"></param>
        /// <param name="isNew"></param>
        /// <param name="refs"></param>
        public GadagetMessage(GadagetMessageCollection parentCollection, int id, string refId, string subj, string from, string fromName, bool isNew, string refs)
        {
            _parentCollection = parentCollection;

            ID = id;
            RefID = refId;
            Subj = subj;
            From = from;
            FromName = fromName;
            IsNew = isNew;

            RefsString = refs != null ? refs : string.Empty;
        }
    }
}
